<?php
namespace Tools\Controller;
use Common\Controller\AdminbaseController;

class AdminAdviseController extends AdminbaseController{

	protected $advise_model;

	public function _initialize() {
		parent::_initialize();
		$this->advise_model = D("ToolsAdvise");

	}

	// 后台意见列表
	public function index(){
//		两表查询出相关人物
//		$ads=$this->advise_model
//			->alias("a")
//			->field('a.*,b.user_nicename')
//			->join("__USERS__ as b on a.userid = b.id")
//			->select();
		$ads=M('tools_advise')->select();
		foreach($ads as $v){
			$uid = $v['userid'];
			$user = M('users')->field('user_nicename')->where("id = '$uid'")->find();
			$v['username'] = $user['user_nicename'];
			$a[] = $v;
		}
		
		
		$this->assign("ads",$a);
		$this->display();
	}

	//反馈添加
	public function add(){
		$this->display();
	}

	// 反馈添加提交
	public function add_post(){
		if(IS_POST){
			$data['userid']=I("userid");
			$data['title']=I("title");
			$data['mobile']=I("mobile");
			$data['email']=I("email");
			$data['content']=I("content");
			$data['time']=time();
			if ($this->advise_model->create($data)!==false){
				if ($this->advise_model->add($data)!==false) {
					$this->success('添加成功！', U("Portal/about/advise"));
				} else {
					$this->error('添加失败！');
				}
			} else {
				$this->error($this->advise_model->getError());
			}
		}
	}


}